/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyectotsm;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JSlider;

/**
 * Clase Manager.java
 * 
 * Clase que gestiona el cambio de imagen del Jpanel
 * que muestra el video, extiende a la clase Runnable
 * ya que es un thread
 *
 * @author srgank
 * @author juancarlos
 * @author gabriel
 */
public class Manager implements Runnable {

    // Atributos
    private GUI gui;
    private JSlider progress;
    private boolean runing;

    /**
     * Constructor con parametros
     * @param gui interfaz grafica del programa
     */
    public Manager(GUI gui) {
        this.gui = gui;
        runing = false;
    }

    /**
     * Metodo que ejecuta el thread
     */
    public void run() {
        double time1 = System.currentTimeMillis();
        double time2;
        int count = 0;
        while (true) {

            try {
                gui.paintComponents(gui.getGraphics());
                time2 = System.currentTimeMillis();
                count++;
                if (time2 - time1 >= 1000) {
                    if (gui.isruning()) {
                        gui.setFps(count);
                    }

                    time1 = time2;
                    count = 0;
                }
                Thread.sleep(25);

            } catch (InterruptedException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
